﻿using SqlSugar;
using System.Configuration;

namespace MesBSW.Tools
{
    /// <summary>
    /// SqlSugar链接
    /// </summary>
    public class SqlSugares
    {

        public static SqlSugarClient GetInstance()
        {
            string connectionString = GetConnectionString();

            // 创建 SqlSugarClient 实例
            var db = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString = connectionString,
                DbType = DbType.SqlServer, // 根据你的数据库类型调整
                IsAutoCloseConnection = true, // 自动关闭连接
                InitKeyType = InitKeyType.Attribute // 初始化主键和自增列信息
            });

            return db;
        }

        public static string GetConnectionString()
        {
            string connectionString = ConfigurationManager.ConnectionStrings["MesDB"].ConnectionString;
            return connectionString;
        }
    }
}
